package com.dk.controller;

import com.dk.pojo.TRole;
import com.dk.service.RoleService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("role")
public class RoleController {

    @DubboReference
    private RoleService roleService;

    @RequestMapping("toShow")
    public String toShow(){

        return "role/show";
    }

    @RequestMapping("getInfo")
    @ResponseBody
    public List<TRole> getInfo() {

        List<TRole> list = roleService.getInfo();

        return list;
    }

    @RequestMapping("deleteInfo")
    @ResponseBody
    public boolean deleteInfo(Integer roleId) {

        return roleService.deleteInfo(roleId);
    }

    @RequestMapping("toAdd")
    public String toAdd() {

        return "role/add";
    }

    @RequestMapping("addInfo")
    @ResponseBody
    public boolean addInfo(TRole tRole,Integer[] mids) {

        return roleService.addInfo(tRole, mids);
    }

    @RequestMapping("toUpdate")
    public String toUpdate(Integer roleId, Model model) {

        TRole role = roleService.toUpdate(roleId);

        model.addAttribute("role",role);

        return "role/update";
    }

    @RequestMapping("updateInfo")
    @ResponseBody
    public boolean updateInfo(TRole tRole,Integer[] mids) {

        boolean b = roleService.updateInfo(tRole,mids);

        return b;
    }
}
